Image Annotation
Search "cmd" from windows, run as administrator
.
Navigate to your Documents folder
cd "%USERPROFILE%\Documents" && cd yolo_projects
mkdir dataset
Open this website, https://universe.roboflow.com/college-ojdd3/garbagedetectionapi/dataset/1
Click "Coco Jason" for downloading
unzip the folder
Copy a folder called "train", \GarbageDetectionAPI.v1i.coco\train to folder, "dataset"
like this:
Create a python file
cd dataset/train
notepad covert-jason.py
import json
import os
# Load your Roboflow COCO JSON file
with open("_annotations.coco.json") as f:
coco = json.load(f)
# Build category lookup
categories = {cat["id"]: cat["name"] for cat in coco["categories"]}
# Build image lookup
images = {img["id"]: img for img in coco["images"]}
# Optional: define your image path prefix for Label Studio to locate the images
IMAGE_PATH_PREFIX = "/data/local-files/?d=train/"
# Collect annotations per image
annotations_by_image = {}
for ann in coco.get("annotations", []):
img_id = ann["image_id"]
bbox = ann["bbox"] # [x, y, width, height]
category_id = ann["category_id"]
image = images[img_id]
width = image["width"]
height = image["height"]
# Normalize coordinates for Label Studio
x = bbox[0] / width * 100
y = bbox[1] / height * 100
w = bbox[2] / width * 100
h = bbox[3] / height * 100
result = {
"from_name": "label",
"to_name": "image",
"type": "rectanglelabels",
"value": {
"x": x,
"y": y,
"width": w,
"height": h,
"rectanglelabels": [categories[category_id]],
},
}
if img_id not in annotations_by_image:
annotations_by_image[img_id] = []
annotations_by_image[img_id].append(result)
# Convert to Label Studio format
label_studio_data = []
for img_id, image in images.items():
entry = {
"data": {"image": IMAGE_PATH_PREFIX + image["file_name"]},
"annotations": [{"result": annotations_by_image.get(img_id, [])}],
}
label_studio_data.append(entry)
# Save to file
with open("label_studio_format.json", "w") as f:
json.dump(label_studio_data, f, indent=2)
print("Conversion complete. Output saved to label_studio_format.json.")
print("Categories:")
for cat_id, cat_name in categories.items():
print(f"{cat_id}: {cat_name}")
python covert-jason.py
copy the categories from the terminal:
Going back the main folder:
cd "%USERPROFILE%\Documents" && cd yolo_projects
cd venv39 && Scripts\activate
SET DATA_UPLOAD_MAX_NUMBER_FILES=10000
set LOCAL_FILES_SERVING_ENABLED=true
set LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=%USERPROFILE%\\Documents\\yolo_projects\\datasets
or
set LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=C:\\Users\\111872\\Documents\\yolo_projects\\datasets
Label-studio start
click the save button.
click settings
Head to the project settings and select Cloud Storage.
Click Add Source Storage and choose Local files from the Storage Type options.
Set the Absolute local path C:\Users\%USERPROFILE%\Documents\yolo_projects\datasets\train.
Select Add storage to confirm the setup.
Check Image Access: http://localhost:8080/data/local-files/?d=/train/batch_01_frame_5_jpg.rf.4b2f849f8838161c9b480a6979099fad.jpg
Go to import
find "label_studio_format.json" from "C:\Users%USERPROFILE%\Documents\yolo_projects\datasets\train"
Click "import" button